package cn.com.yusys.yusp.mobile.service;

import cn.com.yusys.yusp.commons.mapper.QueryModel;
import cn.com.yusys.yusp.mobile.repository.mapper.CustomerMainBodyVisitMapper;
import cn.com.yusys.yusp.mobile.repository.mapper.CustomerVisitMapper;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author yangcheng
 */
@Service
public class CustomerMainBodyVisitService {

    @Resource
    CustomerMainBodyVisitMapper customerMainBodyVisitMapper;

    public List<Map<String, Object>> getCustomerMainBodyVisitList(QueryModel queryModel){
        String roleId= (String) queryModel.getCondition().get("roleId");
        String orgId = (String)queryModel.getCondition().get("orgId");

        PageHelper.startPage(queryModel.getPage(), queryModel.getSize());
        List<Map<String, Object>> list = null;
        //分行行长查询显示其所有属于其所属的机构下客户
        if (orgId.equals("070667XN0") || orgId.equals("070667XN1") ||orgId.equals("070667860") ||orgId.equals("070667XN3")){
            queryModel.getCondition().put("roleLevel", "1");
            list = customerMainBodyVisitMapper.getCustomerMainBodyVisitList(queryModel);
            return list;
        }
        //查询支行下所属的所有客户经理的用户 Sub-branch Manager
        //客户经理
        if (roleId.equals("R0001") || roleId.equals("R0002") || roleId.equals("R0009")){
            queryModel.getCondition().put("roleLevel", "3");
            list = customerMainBodyVisitMapper.getCustomerMainBodyVisitList(queryModel);
        }
        //查询所有用户
        //总行管理员
        if (roleId.equals("R0008") || roleId.equals("R0007") || roleId.equals("R001")){
            queryModel.getCondition().put("roleLevel", "0");
            list = customerMainBodyVisitMapper.getCustomerMainBodyVisitList(queryModel);
        }
        //支行行长查询，显示其机构下所有客户
        if (roleId.equals("R0006") || roleId.equals("R0005") || roleId.equals("R0003") || roleId.equals("R0004")){
            queryModel.getCondition().put("roleLevel", "2");
            list = customerMainBodyVisitMapper.getCustomerMainBodyVisitList(queryModel);
        }
        PageHelper.clearPage();
        return list;
    }
    public Map<String, Object> getCustomerMainBodyDetail(QueryModel queryModel) {
        Map<String, Object> customerMainBodyDetail = customerMainBodyVisitMapper.getCustomerMainBodyDetail(queryModel);
        return  customerMainBodyDetail ;
    }

    public Integer updateCustomerMainBodyDetail(Map map) {
        if(map.size() ==0){
            return 0;
        }
        Integer updateRecords = customerMainBodyVisitMapper.updateCustomerMainBodyDetail(map);
        if(updateRecords>0){
            customerMainBodyVisitMapper.updateMainBodyVisitStatus(map);
        }
        return  updateRecords ;

    }

    public Map<String, Object> getFinanceDetail(QueryModel queryModel) {
        Map<String, Object> financeDetail = customerMainBodyVisitMapper.getFinanceDetail(queryModel);
        return  financeDetail ;
    }

    public Integer updateFinanceDetail(Map map) {
        if(map.size() ==0){
            return 0;
        }
        Integer updateRecords = customerMainBodyVisitMapper.updateFinanceDetail(map);
        return  updateRecords ;
    }

    public Map<String, Object> getManageInfo(QueryModel queryModel) {
        Map<String, Object> manageInfo = customerMainBodyVisitMapper.getManageInfo(queryModel);
        return  manageInfo ;
    }

    public Integer updateManageInfo(Map map) {
        if(map.size() ==0){
            return 0;
        }
        Integer updateRecords = customerMainBodyVisitMapper.updateManageInfo(map);
        return  updateRecords ;
    }

    public  Map<String, Object>  getCustomerMainBodyParticulars(QueryModel queryModel) {
        Map<String, Object> customerMainBodyParticulars = customerMainBodyVisitMapper.getCustomerMainBodyParticulars(queryModel);
        return  customerMainBodyParticulars ;
    }
}
